{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<section class="panel">
    <header class="panel-heading">
        <h4>反馈列表</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" action="{:url('admin/article/messageList')}">
            <div class="form-group">
                <div class="col-xs-1 no-pd-r">
                    <select name="type" class="form-control" id="type">
                        <option {if $Request.get.type == 'mobile'} selected {/if} value="mobile">电话号码</option>
                        <!-- <option {if $Request.get.type == 'nick_name'} selected {/if} value="nick_name">昵称</option> -->
                    </select>
                </div>
                <div class="col-xs-3 no-pd-l">
                    <input type="text" id="keyword" value="{$Request.get.keyword}" name="keyword" class="form-control" placeholder="请输入关键词搜索">
                </div>
                <button type="submit" class="btn btn-color">搜索</button>
                <!-- <button type="button" class="btn btn-success" id="export">导出</button> -->
            </div>
        </form>
        <table class="table table-bordered table-striped no-margin">
            <thead>
            <tr>
                <th class="text-center">用户昵称</th>
                <th class="text-center">用户电话</th>
                <th class="text-center">内容</th>
                <!-- <th class="text-center">状态</th> -->
                <th class="text-center">提交时间</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            {if !empty($list)}
                {foreach $list as $entity}
                <tr>
                    <td style="vertical-align: middle" class="text-center">
                        {$entity->nick_name}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {$entity->mobile}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        {$entity->content}
                    </td>
                    <!-- <td style="vertical-align: middle" class="text-center">
                        {$entity->status == 1 ? '未回复' : '已回复'}
                    </td> -->
                    <td style="vertical-align: middle" class="text-center">
                        {$entity->getCreateTime()}
                    </td>
                    <td style="vertical-align: middle" class="text-center">
                        <!-- <a onclick="reply(this)" data-id="{$entity->message_id}" data-uid="{$entity->user_id}" class="btn btn-xs btn-info">回复</a> -->
                        <a data-url="{:url('article/deleteMsg',['id'=>$entity->message_id])}" onclick="main.ajaxDelete(this)"
                       data-msg="确定要删除该留言吗？" class="btn btn-xs btn-danger">删除</a>
                    </td>
                </tr>
                {/foreach}
            {else /}
            <tr class="text-center">
                <td colspan="5">暂无数据</td>
            </tr>
            {/if}
            </tbody>
        </table>
        <div class="page">
            {:htmlspecialchars_decode($list->render())}
        </div>
    </div>
</section>
{/block}


{block name="footer"}
<form action="{:url('admin/article/exportMessage')}" id="exportForm">
    <input type="hidden" name="type" id="e_type">
    <input type="hidden" name="keyword" id="e_keyword">
    <input type="hidden" name="product_id" id="e_product_id">
    <input type="hidden" name="status" id="e_status">
</form> 
<script>
    $("#export").click(function(){
        var product_id = $("#product_id").val();
        var keyword = $("#keyword").val();
        var type = $("#type").val();
        var status = $("#status").val();
        $('#e_product_id').val(product_id);
        $('#e_keyword').val(keyword);
        $('#e_type').val(type);
        $('#e_status').val(status);
        $("#exportForm").submit();
    })
    function reply(e){
        var id = $(e).attr('data-id');
        var uid = $(e).attr('data-uid');
        var content = '<div class="text-center" style="border-top:1px solid #eee;padding-top: 20px">' +
                '<form class="form-horizontal" id="reply_form" method="post" onsubmit="return false" role="form">' +
                '<div class="form-group"><textarea id="reply_content" class="form-control" rows="5" > </textarea></form></div>';

        $.confirm({
            title: '<strong style="color: #c7254e;font-size: 16px">回复反馈</strong>',
            content: content,
            confirmButton: '确定',
            confirmButtonClass: 'btn btn-info',
            cancelButton: '取消',
            cancelButtonClass: 'btn btn-danger',
            animation: 'scaleY',
            theme: 'material',
            confirm: function () {
                var content = $("#reply_form").find("#reply_content").val();
                if(content==''){
                    main.waringAlert('请输入回复内容');
                    return false;
                }
                $.ajax({
                    url: "{:url('article/replyMsg')}",
                    method: 'POST',
                    data:{
                        id: id,
                        user_id: uid,
                        content: content
                    },
                    dataType: 'json',
                    success: function (response) {
                        if(response.code == 1){
                            main.waringAlert(response.message)
                        }else{
                            window.location.reload();
                            return false;
                        }
                    },
                })
            }

        });
    }
</script>
{/block}